//
//  ProductInfocell.swift
//  Wmsmobile
//
//  Created by Nick xu on 16/8/5.
//  Copyright © 2016年 hddden. All rights reserved.
//

import UIKit
fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
  switch (lhs, rhs) {
  case let (l?, r?):
    return l < r
  case (nil, _?):
    return true
  default:
    return false
  }
}

fileprivate func > <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
  switch (lhs, rhs) {
  case let (l?, r?):
    return l > r
  default:
    return rhs < lhs
  }
}


class ProductInfocell: FounctionBaseCell, displayDetailProtocol {
    //MARK: - property
    var dispalyKey: String?
    override var info: [String : String]?{
        didSet{
            self.dispalyKey = info!["keyToDisplay"]
        }
    }
    var keyToDisplay: String?{
        set{
            dispalyKey = newValue
        }
        get{
            return dispalyKey
        }
    }
    lazy fileprivate var infoView: UILabel = {
        let label = UILabel()
        label.textColor = UIColor.hexStringToUIColor("#666666")
        label.font = UIFont.systemFont(ofSize: self.getFont())
        label.numberOfLines = 0
//        label.backgroundColor = UIColor.redColor()
       
        return label
    }()
    
    //MARK: - life cycle
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: UITableViewCellStyle.default, reuseIdentifier: "ProductInfocell")
        self.setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.setUpUI()
    }
    
    required init() {
        super.init(style: UITableViewCellStyle.default, reuseIdentifier: "ProductInfocell")
        self.setUpUI()
    }
    //MARK: - public
    override func clearContent() {
        self.infoView.text = ""
    }
    //MARK: - private
    func setUpUI(){
//        self.textLabel?.adjustsFontSizeToFitWidth = true
        self.addSubview(self.infoView)
        infoView.snp.makeConstraints { (make) in
            make.leading.equalTo(self).offset(inputViewToCellSpace-10)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.trailing.equalTo(self).offset(-FTCellHorizontalSpace)
        }
    }
    
    //MARK: - delegate
    func setDetail(_ string: String){
        if string.contains("T") && string.contains("-"){ //区分时间信息
           self.infoView.text = string.components(separatedBy: "T").first
        }else{
            self.infoView.text = string
        }
    }
    func isEmpty() -> (Bool) {
        return self.infoView.text?.characters.count > 0 ? false : true
    }

}
